package com.geline.demo.config;

import com.baomidou.mybatisplus.autoconfigure.ConfigurationCustomizer;
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
import com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@MapperScan(basePackages = {"com.geline.**.mapper"})
@EnableTransactionManagement
@Configuration
public class MyBatisPlusConfig {

    @Bean
    public ConfigurationCustomizer configurationCustomizer() {
        return configuration -> {
            //设置Map.key->CamelKey（没有转换方法会失败，采用代码手动设置）
            //object-wrapper-factory: com.baomidou.mybatisplus.extension.MybatisMapWrapperFactory
            configuration.setObjectWrapperFactory(new MybatisMapWrapperFactory());
        };
    }

    // 自定义ID 生成器
    @Bean
    public IdentifierGenerator identifierGenerator() {
        return new DefaultIdentifierGenerator();
    }
}
